package com.lanou.userLogin.cart.web.servlet;

import com.lanou.userLogin.cart.domin.CartItem;
import com.lanou.userLogin.cart.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/cartDeleteOneServlet")
public class CartDeleteOneServlet extends HttpServlet {

    private CartService cs = new CartService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        List<CartItem> cartItems = (List<CartItem>) session.getAttribute("cartItemList");
        String bid = (String) session.getAttribute("bid");
        System.out.println(bid);
        List<CartItem> ci = cs.cartDeleteOne(bid, cartItems);
        for (CartItem cit : ci) {
            System.out.println(cit);
        }
        req.getRequestDispatcher("/jsps/cart/list.jsp").forward(req,resp);
    }
}
